# 这个是什么呀，大家一起跟我说：“迭 代 器 ！”
# 前面我已经用过yield了，大家应该已经知道这个东西有多好玩了，这里我们直接使用迭代器
# 来代替之前的p列表，用来存储素数。
# 就省去很多内存消耗啦~（不过是不是边判断是不是素数，边记录距离也可以？emmmmm，不重要啦）
# 这样看起来比较好理解！
def p():
    # 这里也可以简单地做点手脚， 从奇数开始，步长改为2，记得2要特判，不过好像影响不大。。
    if l == 2: yield 2
    l1 = l if l % 2 else l + 1
    for i in range(l1, r + 1, 2):
        if a[i]: yield i

l, r = map(int, input().split())
# 因为1-8000000中最大的间距就是4652353和4652507了，加了这个，可以保证最多判断400多w次
if l <= 4652353: r = min(4652507, r)
# 素数最小为2
l = max(l, 2)
n = r
a = [True] * (n + 1)
i = 2
while i * i <= n:
    if a[i]:
        j = (n - (i * i)) // i + 1
        a[i * i::i] = [False] * j
    i += 1
p = p()
try:
    x = next(p)
    y = next(p)
except:
    print("There are no adjacent primes.")
else:
    mn, mx = y - x, y - x
    mn1, mx1 = (x, y), (x, y)
    while True:
        x = y
        try:
            y = next(p)
        except:
            break
        z = y - x
        if z < mn:
            mn = z
            mn1 = (x, y)
        if z > mx:
            mx = z
            mx1 = (x, y)
    print(f"{mn1[0]},{mn1[1]} are closest, {mx1[0]},{mx1[1]} are most distant.")

'''
def pp():
    for i in range(max(l, 2), r + 1):
        if a[i]: yield i

from random import randint as ri
ll = [(50, 100), (5000, 10000), (100000, 1000000), (7230332, 7230332), (4800000, 5000000), (1, 1)]
rr = [(101, 200), (10001, 20000), (1000001, 2000000), (7230478, 7230478), (7000000, 7000000), (8000000, 8000000)]
for ww in range(len(ll)):
    l = ri(*ll[ww])
    r = ri(*rr[ww])
    with open(f"{ww + 1}.in", 'w') as f:
        f.write(f"{l} {r}")
    s_o = ""
    print(l, r)
    n = r
    a = [True] * (n + 1)
    i = 2
    while i * i <= n:
        if a[i]:
            j = (n - (i * i)) // i + 1
            a[i * i::i] = [False] * j
        i += 1
    p = pp()
    try:
        x = next(p)
        y = next(p)
    except:
        s_o = "There are no adjacent primes."
    else:
        mn, mx = y - x, y - x
        mn1, mx1 = (x, y), (x, y)
        while True:
            x = y
            try:
                y = next(p)
            except:
                break
            z = y - x
            if z < mn:
                mn = z
                mn1 = (x, y)
            if z > mx:
                mx = z
                mx1 = (x, y)
        s_o = f"{mn1[0]},{mn1[1]} are closest, {mx1[0]},{mx1[1]} are most distant."
    with open(f"{ww + 1}.out", 'w') as f:
        f.write(s_o)
'''
# 数论太难了，我弃坑了
# -------------------------------------------------------------------------------

# 比赛环境为python3.8.6版本自带的IDLE，最好早点熟悉一下。。这个东西的提示时有时无

# 菜单栏最右边的Help的Python Docs 比赛时候也可以看，不过建议还是提前多了解了解，

# 比赛的时候至少知道在文档找什么能用的上。
